package main

import "fmt"

func Find(slice []int, target int) (index int) {
	defer func() {
		if r := recover(); r != nil {
			fmt.Println("Recovered from panic:", r)
			return
		}
	}()

	index = FindIndex(slice, target)
	if index == -1 {
		panic("Target value not found in slice")
	}

	return index
}

func FindIndex(slice []int, target int) int {
	for i, v := range slice {
		if v == target {
			return i
		}
	}

	return -1
}

func main() {
	slice := []int{10, 20, 30, 40, 50}
	target := 35

	result := Find(slice, target)
	fmt.Printf("Target %d found at index %d\n", target, result)
}
